package ch13;

// DeleteCustomer.java
// Represents a delete customer ATM change
import java.util.ArrayList;

public class DeleteCustomer extends Option {
	private Keypad keypad;

	// DeleteCustomer constructor
	private ArrayList<String> stringArray = new ArrayList<String>();
	public DeleteCustomer(int userID, Screen atmScreen,
			BankDatabase atmBankDatabase, Keypad atmKeypad) {
		super(userID, atmScreen, atmBankDatabase);

		keypad = atmKeypad;

	} // end DeleteCustomer constructor

	// performs the change (option)
	public void execute() {
		// get references to bank database and screen
		BankDatabase bankDatabase = getBankDatabase();
		Screen screen = getScreen();
		
		// gets all customers from the customerList ArrayList from BankDatabase
		ArrayList<Customer> customers = bankDatabase.getCustomerList();
		int x = 1;	// to run while

		
		stringArray.clear();
		stringArray.add("Enter the CustomerID you wish to delete,  ");
		stringArray.add("or press 6 to exit to your menu:  ");
		screen.setKasse(stringArray, 10);
		
		// lets the user type the customerID he wishes to delete
		int customerID = keypad.getInput();
			// compares the new customer-object currencCustomer with the ArrayList of customers from BankDatabase
			for (Customer currentCustomer : customers) {
				// return current customer if match found
				if (currentCustomer.getCustomerID() == customerID) {
					x = 1;
					break;
				}	// end if statement
				else 
				{
					x = 2;
					break;
				}	// end else statement
			}	// end for loop
			
			// exits if customer chooses 6
			if (customerID == 6)
			{
				return;
			}	// end if
			
			// delete customer if the customer exists
			if (x == 1)
			{
				// removes customer based on customerID
				bankDatabase.removeCustomers(bankDatabase
						.getCustomer(customerID));
				stringArray.clear();
				stringArray.add("Customer " + customerID + " has been deleted ");
				screen.setKasse(stringArray, 10);
			}	// end if
			else { // customer doesn't exist
				stringArray.clear();
				stringArray.add("Customer " + customerID + " does not exist ");
				screen.setKasse(stringArray, 10);
			}	// end else
	}	// end method execute
} // end class DeleteCustomer